
#ifndef _RES_FACTORY_H_
#define _RES_FACTORY_H_

#include <stdint.h>
#include <string>
#include "c2cplatform/library/basic/singleton_t.h"

class CDBOperator2;

class CResFactory
{
    friend class CSingletonT<CResFactory>; 
public:
    int Initialize(
		const char* pszConfigFileName,
		const char* pszDBPartitionConfigFile = "/usr/local/c2cdb/conf/db_partition_config.conf");

    int InitializeForPlv3(
		const char* pszDBHostSvcName,
		const char* pszConfigFileName,
		const char* pszDBPartitionConfigFile = "/usr/local/c2cdb/conf/db_partition_config.conf");

    int InitializeForPlv3_5(
		const char* pszConfigFileName = "/usr/local/c2csvc/global_conf/global_db_conn.xml",
		const char* pszDBPartitionConfigFile = "/usr/local/c2cdb/conf/db_partition_config.conf");

	int Initialize(
			const char* pszDBHost,
			const char* pszDBName,
			const char* pszDBUser,
			const char* pszDBPass,
			const char* pszDBPartitionConfigFile = "/usr/local/c2cdb/conf/db_partition_config.conf");
	
    CDBOperator2* GetDBOperator(uint32_t dwKey);
    CDBOperator2* GetDBOperator(uint32_t dwCmdId, uint32_t dwKey);
    uint32_t GetDBOperatorCnt(uint32_t dwCmdId);

	const char* GetTableSuffixByUinPartition(const char* pszTableName, uint32_t dwQQUin);

	const char* GetTableSuffixByTimePartition(const char* pszTableName, uint32_t dwTime);

	uint16_t GetMaxPartitionNum(const char* pszTableName);

	const char* GetLastErrMsg() const;

	// ex: 0xf1011801
	void AddCmd(const std::string& sCmdId);

private: 
    CResFactory();
    virtual ~CResFactory();
	int InitDBPartition();

private:
    bool m_bInit;
    bool m_bDBPartitionInit;
	std::string m_sDBPartitionConfigFile;
	std::string m_sLastErrMsg;
};

typedef CSingletonT<CResFactory> CResFactorySingleton;
#define RES_FACTORY CResFactorySingleton::Instance() 

#endif /* _RES_FACTORY_H_ */

